package com.hut.bms.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeAspect {
    @Around("execution(* com.hut.bms.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录方法开始的时间
        long begin = System.currentTimeMillis();
        //执行目标方法
        Object proceed = joinPoint.proceed();
        //记录方法结束的时间
        long end = System.currentTimeMillis();
        log.info("执行方法耗时的时间：{}ms",(end - begin));
        return proceed;
    }
}
